package com.wang.designpattern.responsibilitychain;

import com.wang.designpattern.responsibilitychain.domain.AttendanceClockDO;
import org.springframework.beans.BeanUtils;

import java.util.Map;
import java.util.Objects;


/**
 * 早退处理类
 */
public class PmLeaveEarlyAttendanceHandler extends AttendanceHandler{
    public PmLeaveEarlyAttendanceHandler(String name) {
        super(name);
    }

    @Override
    public void processRequest(Map<String, AttendanceClockDO> clockResultDataMap, AttendanceClockDO attendanceClockDO) {

        AttendanceClockDO clockResultData = clockResultDataMap.get(AttendanceConstant.ExceptionType.LEAVE_EARLY.getExceptionType());
        if (Objects.isNull(clockResultData)) {
            clockResultData = new AttendanceClockDO();
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
        }

        //1、0 < “下午下班时间” - “下午实际下班打卡时间” <= 30分钟
        if (DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getPmSetEndTime(),
                attendanceClockDO.getPmEndTime()) > 0 &&
                DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getPmSetEndTime(),
                        attendanceClockDO.getPmEndTime()) <= 30) {
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.LEAVE_EARLY.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+1);
            clockResultData.setExceptionUnit("T");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.LEAVE_EARLY.getExceptionType(), clockResultData);
        }
    }
}
